﻿using System;

using System.Collections.Generic;
using System.Text;

namespace ISB_iCard
{
    class WSUtility
    {

        iCardService.Service1 objiCardService = new ISB_iCard.iCardService.Service1();
        iCardService.Result objResult = new ISB_iCard.iCardService.Result();

        LocalDB objLocalDB = new LocalDB();

        public string URL;
        public bool IsOnline;
        public iCardService.Result PerformHHTransaction(long TxnId, string PeopleId, string StewardId, double Amount, int IsCash)
        {
            iCardService.Result objResult;
            objiCardService.Url = Convert.ToString(MobileConfiguration.Settings["WSURL"]);
            if (IsOnline)
                objResult = objiCardService.PerformHHTransaction(TxnId, PeopleId, StewardId);
            else
            {
                objResult = new ISB_iCard.iCardService.Result();
                objLocalDB.Push(TxnId, PeopleId, StewardId, Amount, IsCash);
                objResult.IsSuccess = true;
                objResult.Message = "NW not available.\nTxn done locally!";
            }
            return objResult;
        }

        public string GetAmountByTxn(string TxnID)
        {
            objiCardService.Url = Convert.ToString(MobileConfiguration.Settings["WSURL"]);
            if (IsOnline)
                return objiCardService.GetAmountByTxn(TxnID);
            else
                return "0.00";
        }

        public iCardService.Result GetItems(string TxnID)
        {
            objiCardService.Url = Convert.ToString(MobileConfiguration.Settings["WSURL"]);

            return objiCardService.GetItems(TxnID);
        }


    }
}
